package com.springboot.wk.aqs;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class AQSMain {

    public static void main(String[] args) throws InterruptedException {
        int count[] = new int[]{1000};
        final CountDownLatch countDownLatch = new CountDownLatch(100);
        MyLock reentrantLock = new MyLock();
        for (int i = 0; i < 100; i++) {
            new Thread(() -> {
                reentrantLock.lock();
                for (int j = 0 ;j<10;j++){
                    count[0]--;
                    System.out.println(Thread.currentThread().getName() + " count = " + count[0]);
                }
                countDownLatch.countDown();
                reentrantLock.unlock();
                System.out.println(Thread.currentThread().getName()+"countDown: "+countDownLatch.getCount());
            }).start();
        }

        countDownLatch.await();
        System.out.println("主线程执行完毕  count 结果："+count[0]);


    }

}


